package com.supermap.dataservice.alltype.dao;

import com.supermap.dubbo.api.alltype.entity.AllType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author lxs
 * @Title:当天各类(咨询,农情,灾情,产品)数据的实时 数据访问层
 * @Description:
 * @date 2018/8/2  11:52
 */
@Mapper
public interface AllTypeDao {

    @Select("select t1.id,t1.`longitude` AS lon,t2.`latitude` AS lat,t2.areaname,count(t1.areacode) as num from  t_agrinfo t1 INNER JOIN t_area t2 on t1.areacode=t2.areacode " +
            "where t1.areacode like #{areaCode} and date(t1.createtime)=date(now()) GROUP BY t1.areacode")
    List<AllType> getAllTypeToAgrList(@Param("areaCode")String areaCode);

    @Select("select t1.id,t1.`longitude` AS lon,t2.`latitude` AS lat,t2.areaname,count(t1.areacode) as num from  t_disaster t1 INNER JOIN t_area t2 on t1.areacode=t2.areacode " +
            "where t1.areacode like #{areaCode} and date(t1.createtime)=date(now()) GROUP BY t1.areacode")
    List<AllType> getAllTypeToDisList(@Param("areaCode")String areaCode);

    @Select("select t1.id,t1.lon,t1.lat,t2.areaname,count(t1.areacode) as num from  t_advisoryinfo t1 INNER JOIN t_area t2 on t1.areacode=t2.areacode " +
            "where t1.areacode like #{areaCode} and date(t1.uploadTime)=date(now()) GROUP BY t1.areacode")
    List<AllType> getAllTypeToAdvList(@Param("areaCode")String areaCode);

    //获取当前区域的农田各类统计
    @Select("select t1.id,t4.type as name,count(t4.type) as num from t_farmland t1 INNER JOIN t_farmcrops t2 on t1.id=t2.farmland\n" +
            "INNER JOIN t_crop t3 on t2.crop=t3.code\n" +
            "INNER JOIN t_crop_type t4 on t4.cropid=t3.id where t1.code like #{areaCode} group by t4.type")
    List<AllType> getFarmCropNumByAreaCode(@Param("areaCode")String areaCode);
}
